//
//  ContrastCustomHeaderView.swift
//  ChanMaMa
//
//  Created by 戴泉明 on 2021/4/21.
//  Copyright © 2021 蝉妈妈-戴泉明. All rights reserved.
//

import UIKit

//总的
class CompareHiddenHeader: UIView {
    var titleLabel = UILabel()
    var totalLabel = UILabel()
    var switchBtn = UISwitch()
    var showDifferenceBlock: ((Bool)->())?

    class func create() -> CompareHiddenHeader {
        let view = CompareHiddenHeader()
        view.isUserInteractionEnabled = true
        view.addSubview(view.titleLabel)
        view.titleLabel.frame = CGRect(x: 0, y: CONTRAST_HEADER_HEIGHT-42, width: CONTRAST_CONFIG_WIDTH, height: 17)
        view.titleLabel.text = "仅看不同"
        view.titleLabel.textColor = UIColor.init(ts_hexString: "#202629")
        view.titleLabel.font = UIFont.boldSystemFont(ofSize: 12)
        view.titleLabel.textAlignment = .center
        view.titleLabel.numberOfLines = 0
        view.addSubview(view.totalLabel)
        view.totalLabel.frame = CGRect(x: 0, y: 25, width: CONTRAST_CONFIG_WIDTH, height: 17)
        view.totalLabel.text = "共5个达人"
        view.totalLabel.font = UIFont.systemFont(ofSize: 12)
        view.totalLabel.textAlignment = .center
        view.totalLabel.textColor = UIColor.init(ts_hexString: "202629")
        view.addSubview(view.switchBtn)
        view.switchBtn.frame = CGRect(x: CONTRAST_CONFIG_WIDTH/2-25, y: 50, width: 50, height: 26)
        view.switchBtn.onTintColor = UIColor.init(ts_hexString: "#FF7752")
        view.switchBtn.addTarget(view, action: #selector(showDifferenceSwitchTarget(swit:)), for: .allTouchEvents)
        
        view.layer.borderWidth = 0.5
        view.layer.borderColor = UIColor.init(ts_hexString: "#E3E4E5").cgColor
        return view
    }
    
    @objc func showDifferenceSwitchTarget(swit:UISwitch) {
        showDifferenceBlock?(swit.isOn)
    }
    
}

//右侧
class CompareRightHeader: UIView {
    var titleLabel =  UILabel()
    var dingBtn = UIButton()
    var deleteBtn = UIButton()
    var dingBlock: (()->())?
    var deleteBlock: (()->())?
    
    class func create() -> CompareRightHeader {
        let view = CompareRightHeader()
        view.isUserInteractionEnabled = true
        view.addSubview(view.titleLabel)
        view.titleLabel.frame = CGRect(x: 0, y: 30, width: CONTRAST_ITEM_WIDTH, height: CONTRAST_HEADER_HEIGHT-30)
        view.titleLabel.text = "名称"
        view.titleLabel.textColor = UIColor.init(ts_hexString: "#202629")
        view.titleLabel.font = UIFont.boldSystemFont(ofSize: 13)
        view.titleLabel.textAlignment = .center
        view.titleLabel.numberOfLines = 0
        view.addSubview(view.dingBtn)
        view.dingBtn.frame = CGRect(x: 0, y: 0, width: 72, height: 20)
        view.dingBtn.setTitle("钉在左侧", for: .normal)
        view.dingBtn.setImage(UIImage(named: "contrast_ding"), for: .normal)
        view.dingBtn.setTitleColor(UIColor.init(ts_hexString: "202629"), for: .normal)
        view.dingBtn.backgroundColor = UIColor.init(ts_hexString: "#F5F6F7")
        view.dingBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        view.dingBtn.addTarget(view, action: #selector(ding), for: .touchUpInside)
        view.addSubview(view.deleteBtn)
        view.deleteBtn.frame = CGRect(x: CONTRAST_ITEM_WIDTH-44, y: 0, width: 44, height: 44)
        view.deleteBtn.setImage(UIImage(named: "contrast_delete"), for: .normal)
        view.deleteBtn.imageEdgeInsets = UIEdgeInsets(top: 5, left: 31, bottom: 31, right: 5)
        view.deleteBtn.addTarget(view, action: #selector(deleteAction), for: .touchUpInside)
        view.layer.borderWidth = 0.5
        view.layer.borderColor = UIColor.init(ts_hexString: "#E3E4E5").cgColor
        return view
    }
    
    @objc func ding() -> Void {
        dingBlock?()
    }
    
    @objc func deleteAction() -> Void {
        deleteBlock?()
    }
    
}


//右侧
class CompareDingHeader: UIView {
    
    var titleLabel = UILabel()
    var cancleDingBtn = UIButton()
    var cancleDingBlock: (()->())?
    
    class func create() -> CompareDingHeader {
        let view = CompareDingHeader()
        view.isUserInteractionEnabled = true
        view.addSubview(view.titleLabel)
        view.titleLabel.frame = CGRect(x: 0, y: 30, width: CONTRAST_ITEM_WIDTH, height: CONTRAST_HEADER_HEIGHT-30)
        view.titleLabel.text = "名称"
        view.titleLabel.textColor = UIColor.init(ts_hexString: "#202629")
        view.titleLabel.font = UIFont.boldSystemFont(ofSize: 13)
        view.titleLabel.textAlignment = .center
        view.titleLabel.numberOfLines = 0
        view.addSubview(view.cancleDingBtn)
        view.cancleDingBtn.frame = CGRect(x: 0, y: 0, width: 72, height: 20)
        view.cancleDingBtn.setTitle("取消钉住", for: .normal)
        view.cancleDingBtn.setImage(UIImage(named: "contrast_cancleding"), for: .normal)
        view.cancleDingBtn.setTitleColor(UIColor.init(ts_hexString: "#FF7752"), for: .normal)
        view.cancleDingBtn.backgroundColor = UIColor.init(ts_hexString: "#FF7752",alpha: 0.1)
        view.cancleDingBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        view.cancleDingBtn.addTarget(view, action: #selector(cancleDing), for: .touchUpInside)
        
        view.layer.borderWidth = 0.5
        view.layer.borderColor = UIColor.init(ts_hexString: "#E3E4E5").cgColor
        return view
    }
    
    @objc func cancleDing() -> Void {
        cancleDingBlock?()
    }
    
}


//添加
class CompareAddHeader: UIView {
    
    var addBtn = UIButton()
    var addBlock: (()->())?
    
    class func create() -> CompareAddHeader {
        let view = CompareAddHeader()
        view.isUserInteractionEnabled = true
        view.addSubview(view.addBtn)
        view.addBtn.frame = CGRect(x: 0, y: 0, width: CONTRAST_ITEM_WIDTH, height: CONTRAST_HEADER_HEIGHT)
        view.addBtn.setImage(UIImage(named: "contrast_add"), for: .normal)
        view.addBtn.setTitle("添加对比", for: .normal)
        view.addBtn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        view.addBtn.setTitleColor(UIColor.init(ts_hexString: "202629"), for: .normal)
        view.addBtn.imageEdgeInsets = UIEdgeInsets(top: -view.addBtn.titleLabel!.bounds.size.height-2, left: -20, bottom: 0, right: -view.addBtn.titleLabel!.bounds.size.width)
        view.addBtn.titleEdgeInsets = UIEdgeInsets(top: 0, left: -view.addBtn.imageView!.bounds.size.width, bottom: -view.addBtn.imageView!.bounds.size.height-2, right: 0)

        view.addBtn.addTarget(view, action: #selector(add), for: .touchUpInside)
        
        view.layer.borderWidth = 0.5
        view.layer.borderColor = UIColor.init(ts_hexString: "#E3E4E5").cgColor
        return view
    }
    
    @objc func add() -> Void {
        addBlock?()
    }
}

